package cn.yhbk.web.modules.manager.Controller;

import cn.yhbk.web.common.api.CommonResult;
import cn.yhbk.web.modules.manager.Pojo.DTO.Comment.TbCommentDto;
import cn.yhbk.web.modules.manager.Pojo.Entity.TbComment;
import cn.yhbk.web.modules.manager.Service.ITbCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 评论表 前端控制器
 * </p>
 *
 * @author 有何不可
 * @since 2023-08-05
 */
@Api(tags = "评论接口")
@Slf4j
@RestController
@RequestMapping("/manager/tbComment")
public class TbCommentController {

    @Autowired
    private ITbCommentService iTbCommentService;

    @ApiOperation("根据ID查询评论")
    @GetMapping("/getCommentInfo")
    public CommonResult<TbCommentDto> getCommentInfo(@RequestParam("id") Long id){
        log.info("查询评论,id:" + id);
        return CommonResult.success(iTbCommentService.queryCommentById(id));
    }

    @ApiOperation("增加评论")
    @PostMapping("/saveComment")
    public CommonResult<String> saveComment(@RequestBody TbComment tbComment){
        log.info("增加评论，" + tbComment);
        Boolean saveCollege = iTbCommentService.insertComment(tbComment);
        if(!saveCollege){
            return CommonResult.failed("保存评论出错");
        }
        return CommonResult.success("保存成功");
    }

    @ApiOperation("修改评论")
    @PutMapping("/updateCollege")
    public CommonResult<String> updateComment(@RequestBody TbComment tbComment){
        log.info("修改评论，" + tbComment);
        Boolean updateCollege = iTbCommentService.updateCommentById(tbComment);
        if(!updateCollege){
            return CommonResult.failed("修改评论出错");
        }
        return CommonResult.success("修改成功");
    }

    @ApiOperation("删除评论")
    @PostMapping("/deleteCollege")
    public CommonResult<String> deleteComment(@RequestBody TbComment tbComment){
        log.info("删除评论，" + tbComment);
        Boolean deleteCollege = iTbCommentService.deleteCommentById(tbComment.getId());
        if(!deleteCollege){
            return CommonResult.failed("删除评论出错");
        }
        return CommonResult.success("删除成功");
    }

}
